package com.example.videoproject.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.videoproject.pojo.Person;
import com.example.videoproject.pojo.Users;
import com.example.videoproject.service.IPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 二组
 * @since 2022-07-23
 */
@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private IPersonService iPersonService;

    //注册使用者
    @RequestMapping("EnrollPerson")
    public boolean EnrollUsers(Person person){
        person.setUdeleted(0);
        person.setUimage("http://video-project.test.upcdn.net/video/admin.jpg");
        boolean rs = iPersonService.save(person);
        return rs;
    }



    @PostMapping("/insert")
    public boolean insert(Person person){
        person.setUdeleted(0);
        person.setUimage("http://video-project.test.upcdn.net/video/admin.jpg");
        boolean ret = iPersonService.save(person);
        return ret;
    }
    @PostMapping("/update")
    public boolean update(Person person){
        person.setUdeleted(0);
        boolean ret = iPersonService.updateById(person);
        return ret;
    }
    @PostMapping("/selectPerson")
    public Person selectPerson(String uid){
        QueryWrapper<Person> qw1 = new QueryWrapper();
        qw1.eq("uid",uid);
        Person person1 = iPersonService.getOne(qw1);
        return person1;

    }
    @PostMapping("/delete")
    public boolean delete(String uid){
        boolean ret = iPersonService.removeById(uid);
        return ret;
    }

    /*    @GetMapping("/getAllPerson")
        public List<Person> getAllPerson(){
            List<Person> list = personService.list(null);
            return list;
        }*/
    @GetMapping("/getAllPerson")
    public List<Person> listUsers(Person person){
        QueryWrapper <Person> qw2 = new QueryWrapper<Person>();
        if(person.getUid()!=null){
            qw2.like("uid",person.getUid());
        };
        if(person.getUname()!=null){
            qw2.like("uname",person.getUname());
        };
        if(person.getUphone()!=null){
            qw2.like("uphone",person.getUphone());
        };
        if(person.getUemail()!=null){
            qw2.like("uemail",person.getUemail());
        };
        List<Person> list = iPersonService.list(qw2);
        return list;
    }


}

